from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import QIcon, QPalette, QBrush, QPixmap, QFont
from PyQt5.QtWidgets import QApplication, QDialog, QHBoxLayout, QVBoxLayout
import sys
import matplotlib
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
from matplotlib.backends.backend_template import FigureCanvas
from matplotlib.figure import Figure
import numpy as np
from PIL import Image
import os
import matplotlib.pyplot as plt
from pylab import mpl
mpl.rcParams['font.sans-serif'] = ['SimHei']  # 修改为中文标签
mpl.rcParams['axes.unicode_minus'] = False  # 正常显示负号

class Canvas(FigureCanvasQTAgg):
    def __init__(self, parent=None, width=5, height=4, dpi=100):
        self.fig = Figure(figsize=(width, height), dpi=dpi)
        FigureCanvasQTAgg.__init__(self, self.fig)
        self.axes = self.fig.add_subplot(111)
        self.setParent(parent)

        self.wall_x = None
        self.wall_y = None
        self.one_object_x = []
        self.one_object_Y = []
        self.color = ['r','c', 'b','m','y','lightcoral','darkgreen','blueviolet','r','c', 'b','m','y']
        self.updata_figure()
        FigureCanvasQTAgg.updateGeometry(self)

    def updata_figure(self, x=None, y = None, name=None,object_x = None,object_y = None):
        self.axes.cla()
        self.axes.set_title(name, fontsize='small')
        self.axes.set_xlim([-10, 10])
        self.axes.set_ylim([45, 120])
        self.axes.tick_params(labelsize=5)  # 设置xy字体大小
        # c = self.color[0:len(x)]
        if object_x != None:
            self.axes.scatter(object_x, object_y, marker='.', c= 'g', cmap='jet', s=1, linewidths=None)
        self.one_object_x = x
        self.one_object_y = y
        if x != None:
            self.axes.scatter(x, y, marker='.', c=self.color[0:len(x)], cmap='jet',s=2,linewidths=None)
        if ( self.wall_x != None and self.wall_y != None):
            self.axes.scatter(self.wall_x, self.wall_y,marker='|', c='k', s = 1, linewidths=1)
        self.draw()
    def updata_figure_fusion(self, x=None, y = None, name=None,object_x = None,object_y = None):
        self.axes.cla()
        self.axes.set_title(name, fontsize='small')
        self.axes.set_xlim([-10, 10])
        self.axes.set_ylim([45, 120])
        self.axes.tick_params(labelsize=5)  # 设置xy字体大小
        if object_x != None:
            self.axes.scatter(object_x, object_y, marker='.', c='g', cmap='jet', s=1, linewidths=None)
        self.one_object_x = x
        self.one_object_y = y
        if x!= None:
            self.axes.scatter(x, y, marker='.', c=self.color[0:len(x)], cmap='jet',s=2,linewidths=None)
        if ( self.wall_x != None and self.wall_y != None):
            self.axes.scatter(self.wall_x, self.wall_y,  marker='|',c='k', s = 1.5, linewidths=2)
        self.draw()

    def updata_figure_wall(self, wall_x=None, wall_y=None,name=None,object_x = None,object_y = None):
        self.axes.cla()
        self.axes.set_title(name, fontsize='small')
        self.axes.set_xlim([-10, 10])
        self.axes.set_ylim([45, 120])
        self.axes.tick_params(labelsize=5)  # 设置xy字体大小
        self.wall_x = wall_x
        self.wall_y = wall_y
        self.axes.scatter(self.wall_x, self.wall_y, marker='|',  c='k', s=1, linewidths=1)
        if object_x != None:
            self.axes.scatter(object_x, object_y, marker='.', c='g', cmap='jet', s=1, linewidths=None)
        if self.one_object_x != None:
            self.axes.scatter(self.one_object_x, self.one_object_y, marker='.', c=self.color[0:len(self.one_object_x)], s=2, linewidths=None)
        self.draw()
    def updata_figure_fusion_wall(self, x=None, y=None,name=None,object_x = None,object_y = None):
        self.axes.cla()
        self.axes.set_title(name, fontsize='small')
        self.axes.set_xlim([-10, 10])
        self.axes.set_ylim([45, 120])
        self.axes.tick_params(labelsize=5)  # 设置xy字体大小
        self.wall_x = x
        self.wall_y = y
        self.axes.scatter(self.wall_x, self.wall_y, marker='|',  c='k', s = 1.5, linewidths=2)
        if object_x != None:
            self.axes.scatter(object_x, object_y,  marker='.', c='g', cmap='jet', s=1, linewidths=None)
        if self.one_object_x != None:
            self.axes.scatter(self.one_object_x, self.one_object_y, marker='.',c = self.color[0:len(self.one_object_x)], s=2, linewidths=None)
        self.draw()

class ToolsUi(QDialog):
    # 信号槽机制：设置一个信号，用于触发接收区写入动作
    # signal_write_msg = QtCore.pyqtSignal(str)   #写信息
    signal_write_rader_msg = QtCore.pyqtSignal(str)  # 雷达写信息
    signal_write_laser_msg = QtCore.pyqtSignal(str)  # 激光写信息
    signal_write_timeRegistration_msg = QtCore.pyqtSignal(str)  # 时间配准写信息
    signal_write_fusion_msg = QtCore.pyqtSignal(str)  # 数据融合写信息

    signal_wall_rader_flush = QtCore.pyqtSignal(list, list,str,str,str,str)  # 墙体数据刷新

    signal_radar_flush = QtCore.pyqtSignal(list)  # 雷达触发
    signal_laser_flush = QtCore.pyqtSignal(list)  # 激光触发    激光数据需要经过转换之后，才可以显示
    signal_fusion_flush = QtCore.pyqtSignal(list)  # 融合触发   融合需要的时候喊汤俊锋改成list

    # signal_object_flush = QtCore.pyqtSignal(np.ndarray)

    def __init__(self, num):
        super(ToolsUi, self).__init__()
        self.num = num
        self._translate = QtCore.QCoreApplication.translate
        self.radar_images = None
        self.setObjectName("TCP-UDP")
        font = QtGui.QFont()
        font.setFamily("Yuppy TC")
        font.setPointSize(8)
        self.setFont(font)

        self.setAcceptDrops(False)
        self.setSizeGripEnabled(False)

        self.person_location = None

        self.object_radar_x = []
        self.object_radar_y = []
        self.object_laser_x = []
        self.object_laser_y = []
        self.object_fusion_x = []
        self.object_fusion_y = []

        # 定义控件
        self.pushButton_get_ip = QtWidgets.QPushButton()  # 重新获取IP按键
        self.pushButton_link = QtWidgets.QPushButton()  # 连接网络按钮
        self.pushButton_unlink = QtWidgets.QPushButton()  # 断开网络按钮

        self.pushButton_clear = QtWidgets.QPushButton()  # 清除消息按钮
        self.pushButton_exit = QtWidgets.QPushButton()  # 退出系统 按钮
        self.pushButton_show_figure = QtWidgets.QPushButton()  # 显示单独显示融合图表 按钮

        self.pushButton_historical_data = QtWidgets.QPushButton()  # 历史数据
        self.pushButton_time_registration = QtWidgets.QPushButton()  # 时间配准

        self.pushButton_radar_turn_add = QtWidgets.QPushButton()  # 加速旋转 按钮
        self.pushButton_radar_turn_reduce = QtWidgets.QPushButton()  # 减速旋转 按钮
        self.comboBox_radar_scan = QtWidgets.QComboBox()  # 扫描

        self.comboBox_radar_scan.addItem("")
        self.comboBox_radar_scan.addItem("")
        self.comboBox_radar_scan.addItem("")
        self.comboBox_radar_scan.addItem("")
        self.comboBox_radar_scan.addItem("")

        self.comboBox_radar_turn = QtWidgets.QComboBox()  # 旋转框

        self.comboBox_radar_turn.addItem("")
        self.comboBox_radar_turn.addItem("")
        self.comboBox_radar_turn.addItem("")
        self.comboBox_radar_turn.addItem("")
        self.comboBox_radar_turn.addItem("")

        self.comboBox_objtect_test = QtWidgets.QComboBox()  # 扫描
        self.comboBox_objtect_test.addItem("single1")
        self.comboBox_objtect_test.addItem("single2")
        self.comboBox_objtect_test.addItem("multi")

        self.label_ip = QtWidgets.QLabel()  # 本机ip
        self.label_port = QtWidgets.QLabel()  # 端口号标签
        self.laser_label_port = QtWidgets.QLabel()  # 激光端口号标签
        self.label_sendto = QtWidgets.QLabel()  # 穿墙雷达IP 标签
        self.laser_label_sendto = QtWidgets.QLabel()  # 激光IP 标签
        self.label_person_location = QtWidgets.QLabel()  # 输入人员位置 标签

        self.label_written = QtWidgets.QLabel()  # 透明战场作战平台 标签

        self.label_detect_number_people = QtWidgets.QLabel()  # 探测人数
        self.label_real_number_people = QtWidgets.QLabel()  # 房长
        self.label_error_number_people = QtWidgets.QLabel()  # 房宽

        self.label_sub_house_length = QtWidgets.QLabel()  # 房长
        self.label_sub_house_width = QtWidgets.QLabel()  # 房宽

        self.lineEdit_ip_local = QtWidgets.QLineEdit()  # 本机ip编辑框
        # self.lineEdit_ip_local.setFixedWidth(115)

        self.lineEdit_port = QtWidgets.QLineEdit()  # 端口号编辑框
        self.lineEdit_port.setText(str(8000))
        self.lineEdit_laser_port = QtWidgets.QLineEdit()  # 激光端口编辑框
        self.lineEdit_laser_port.setText(str(65501))
        self.lineEdit_ip_send = QtWidgets.QLineEdit()  # 穿墙雷达ip 编辑框
        self.lineEdit_ip_send.setText('192.168.4.123')
        self.lineEdit_laser_ip_send = QtWidgets.QLineEdit()  # 激光ip 编辑框
        self.lineEdit_laser_ip_send.setText('192.168.4.110')
        self.lineEdit_person_location = QtWidgets.QLineEdit()  # 人员位置 编辑框

        self.textBrowser_recv_radar = QtWidgets.QTextBrowser()  # 文本浏览框
        self.textBrowser_recv_laser = QtWidgets.QTextBrowser()  # 文本浏览框
        self.textBrowser_recv_fusion = QtWidgets.QTextBrowser()  # 文本浏览框

        self.myfigure_rader = Canvas(self, dpi=150)  # 雷达画布
        self.myfigure_rader.axes.set_title('Radar', fontsize='small')

        self.myfigure_laser = Canvas(self, dpi=150)# 激光画布
        self.myfigure_laser.axes.set_title("Laser", fontsize='small')
        self.myfigure_laser.setFixedHeight(250)
        self.myfigure_fusion  = Canvas(self, dpi=150)  # 总画布
        self.myfigure_fusion.updata_figure_fusion(name="Fusion")
        # self.myfigure_fusion.setFixedWidth(550)
        self.myfigure_fusion.setFixedHeight(350)

        # 定义布局
        self.h_box_1 = QHBoxLayout()
        self.h_box_2 = QHBoxLayout()
        self.h_box_3 = QHBoxLayout()
        self.h_box_4 = QHBoxLayout()
        self.h_box_5 = QHBoxLayout()
        self.h_box_6 = QHBoxLayout()

        self.h_box_number_people = QHBoxLayout()  # 人数显示区域
        self.h_box_exit = QHBoxLayout()  # 透明战场作战平台  与v_box_exit（发送 和退出系统）
        self.h_box_all = QHBoxLayout()  #
        self.h_box_myfigure_fusion = QHBoxLayout()  # 融合水平布局

        self.h_box_myfigure_laser_radar = QHBoxLayout()  # 激光和穿墙雷达画布的水平布局
        self.v_box_set = QVBoxLayout()  # h_box_1 h_box_2 h_box_3 h_box_4 h_box_5 h_box_6垂直布局
        self.v_box_send_recv = QVBoxLayout()  # label_send   v_box_web
        self.v_box_myfigure = QVBoxLayout()  # 画布的垂直布局
        self.v_box_exit = QVBoxLayout()  # 发送 和退出系统
        self.v_box_right = QVBoxLayout()  # 右侧布局
        self.v_box_left = QVBoxLayout()  # 左侧布局


        # 设置字体
        font = QtGui.QFont()
        font.setFamily("Yuppy TC")
        font.setPointSize(10)
        font.setBold(True)
        font.setItalic(False)
        font.setWeight(75)
        font.setStrikeOut(False)
        self.label_real_number_people.setFont(font)
        self.label_detect_number_people.setFont(font)
        self.label_error_number_people.setFont(font)
        self.label_sub_house_length.setFont(font)
        self.label_sub_house_width.setFont(font)

        self.pushButton_unlink.setEnabled(False)  # 断开连接默认不能点击

        self.textBrowser_recv_radar.insertPlainText("雷达坐标%s\n" % self.num)  # 雷达坐标文本浏览框
        self.textBrowser_recv_laser.insertPlainText("激光坐标%s\n" % self.num)  # 激光坐标文本浏览框
        self.textBrowser_recv_fusion.insertPlainText("数据融合坐标%s\n" % self.num)  # 数据融合文本浏览框

        # 调用布局方法和控件显示文字的方法
        self.layout_ui()
        self.ui_translate()

    def layout_ui(self):
        """
        设置控件的布局
        :return:
        """
        # 左侧布局添加
        self.h_box_1.addWidget(self.label_ip)  # 本机ip标签
        self.h_box_1.addWidget(self.lineEdit_ip_local)  # 本机ip编辑框
        self.h_box_1.addWidget(self.comboBox_objtect_test)  # 本机ip编辑框
        self.h_box_1.addStretch(1)  # 增加伸缩量

        self.h_box_2.addWidget(self.label_sendto)  # 雷达IP 标签
        self.h_box_2.addWidget(self.lineEdit_ip_send)  # 雷达IP 编辑框
        self.h_box_2.addWidget(self.label_port)  # 雷达端口号标签
        self.h_box_2.addWidget(self.lineEdit_port)  # 雷达端口号编辑框

        self.h_box_3.addWidget(self.laser_label_sendto)  # 激光IP 标签
        self.h_box_3.addWidget(self.lineEdit_laser_ip_send)  # 激光IP 边界框
        self.h_box_3.addWidget(self.laser_label_port)  # 激光端口号 标签
        self.h_box_3.addWidget(self.lineEdit_laser_port)  # 激光端口号 编辑框

        self.h_box_4.addWidget(self.label_person_location)  # 输入人员位置
        self.h_box_4.addWidget(self.lineEdit_person_location)  # 输入人员位置编辑框

        self.h_box_5.addWidget(self.pushButton_get_ip)  # 重新获取IP按键
        self.h_box_5.addWidget(self.pushButton_link)  # 连接网络按钮
        self.h_box_5.addWidget(self.pushButton_unlink)  # 断开网络按钮

        self.h_box_6.addWidget(self.comboBox_radar_scan)  # 扫描
        self.h_box_6.addWidget(self.comboBox_radar_turn)  # 旋转
        self.h_box_6.addWidget(self.pushButton_radar_turn_add)  # 加速旋转按钮
        self.h_box_6.addWidget(self.pushButton_radar_turn_reduce)  # 减速旋转按钮

        self.v_box_set.addLayout(self.h_box_1)
        self.v_box_set.addLayout(self.h_box_2)
        self.v_box_set.addLayout(self.h_box_3)
        self.v_box_set.addLayout(self.h_box_4)
        self.v_box_set.addLayout(self.h_box_5)
        self.v_box_set.addLayout(self.h_box_6)
        # self.v_box_set.addStretch(1)  # 增加伸缩量

        self.v_box_send_recv.addWidget(self.textBrowser_recv_radar)  # 雷达文本浏览框
        self.v_box_send_recv.addWidget(self.textBrowser_recv_laser)  # 激光文本浏览框
        self.v_box_send_recv.addWidget(self.textBrowser_recv_fusion)  # 数据融合文本浏览框

        self.v_box_exit.addWidget(self.pushButton_clear)  # 清除消息按钮
        self.v_box_exit.addWidget(self.pushButton_historical_data)  # 历史数据按钮
        self.v_box_exit.addWidget(self.pushButton_time_registration)  # 时间配准按钮
        self.v_box_exit.addWidget(self.pushButton_show_figure)  # 显示图表按钮
        self.v_box_exit.addWidget(self.pushButton_exit)  # 退出系统 按钮

        self.h_box_exit.addWidget(self.label_written)  # 透明战场作战平台 标签
        self.h_box_exit.addLayout(self.v_box_exit)

        self.v_box_left.addLayout(self.v_box_set)
        self.v_box_left.addLayout(self.v_box_send_recv)
        self.v_box_left.addLayout(self.h_box_exit)

        # 右侧布局添加
        self.h_box_number_people.addWidget(self.label_detect_number_people)  # 探测人数
        self.h_box_number_people.addWidget(self.label_real_number_people)  #
        self.h_box_number_people.addWidget(self.label_error_number_people)  #
        self.h_box_number_people.addWidget(self.label_sub_house_length)  #
        self.h_box_number_people.addWidget(self.label_sub_house_width)  #

        self.h_box_myfigure_laser_radar.addWidget(self.myfigure_rader)  # 雷达画布垂直布局
        self.h_box_myfigure_laser_radar.addWidget(self.myfigure_laser)  # 激光画布垂直布局

        self.h_box_myfigure_fusion.addWidget(self.myfigure_fusion)  # 融合画布水平布局

        self.v_box_myfigure.addLayout(self.h_box_myfigure_laser_radar)
        self.v_box_myfigure.addLayout(self.h_box_myfigure_fusion)

        self.v_box_right.addLayout(self.h_box_number_people)
        self.v_box_right.addLayout(self.v_box_myfigure)

        # 将左右和图片布局添加到窗体布局
        self.h_box_all.addLayout(self.v_box_left)
        self.h_box_all.addLayout(self.v_box_right)


        # 设置窗体布局到窗体
        self.setLayout(self.h_box_all)

    def ui_translate(self):

        self.setWindowTitle(self._translate("TCP-UDP", "透明战场作战平台-窗口%s" % self.num))
        self.setWindowIcon(QIcon('./data2/tubiao.jpg'))  # 设置软件图标

        # palette = QPalette()
        # palette.setBrush(QPalette.Background, QBrush(QPixmap("./data2/background1.jpg")))
        # self.setPalette(palette)

        self.pushButton_link.setText(self._translate("TCP-UDP", "连接网络"))
        self.pushButton_unlink.setText(self._translate("TCP-UDP", "断开网络"))
        self.pushButton_get_ip.setText(self._translate("TCP-UDP", "重新获取IP"))
        self.pushButton_clear.setText(self._translate("TCP-UDP", "清除消息"))
        self.pushButton_exit.setText(self._translate("TCP-UDP", "退出系统"))
        self.pushButton_show_figure.setText(self._translate("TCP-UDP", "显示图表细节"))
        self.pushButton_historical_data.setText(self._translate("TCP-UP", "历史数据"))
        self.pushButton_time_registration.setText(self._translate("TCP-UDP", "时空配准"))
        self.pushButton_radar_turn_add.setText(self._translate("TCP-UDP", "+"))
        self.pushButton_radar_turn_reduce.setText(self._translate("TCP-UDP", "-"))

        self.comboBox_radar_scan.setItemText(0, self._translate("TCP-UDP", "雷达停止扫描"))
        self.comboBox_radar_scan.setItemText(1,self._translate("TCP-UDP", "雷达启动扫描"))
        self.comboBox_radar_scan.setItemText(2,self._translate("TCP-UDP", "墙体启动融合1"))
        self.comboBox_radar_scan.setItemText(3,self._translate("TCP-UDP", "墙体启动融合2"))
        self.comboBox_radar_scan.setItemText(4,self._translate("TCP-UDP", "墙体停止融合"))

        self.comboBox_radar_turn.setItemText(0,self._translate("TCP-UDP", "云台停止旋转"))
        self.comboBox_radar_turn.setItemText(1,self._translate("TCP-UDP", "云台向左转"))
        self.comboBox_radar_turn.setItemText(2,self._translate("TCP-UDP", "云台向右转"))
        self.comboBox_radar_turn.setItemText(3,self._translate("TCP-UDP", "云台向上转"))
        self.comboBox_radar_turn.setItemText(4,self._translate("TCP-UDP", "云台向下转"))

        # self.comboBox_objtect_test.setItemText(0,self._translate("TCP-UDP", "单目标测试"))
        # self.comboBox_objtect_test.setItemText(1,self._translate("TCP-UDP", "多目标测试"))
        self.label_ip.setText(self._translate("TCP-UDP", "本机地址:"))
        self.label_port.setText(self._translate("TCP-UDP", "雷达端号:"))
        self.laser_label_port.setText(self._translate("TCP-UDP", "激光端口:"))
        self.label_sendto.setText(self._translate("TCP-UDP", "雷达IP:"))
        self.laser_label_sendto.setText(self._translate("TCP-UDP", "激光IP:"))
        self.label_detect_number_people.setText(self._translate("TCP-UDP", "检测人数:"))
        self.label_real_number_people.setText(self._translate("TCP-UDP", "房长:"))
        self.label_error_number_people.setText(self._translate("TCP-UDP", "房宽:"))
        self.label_sub_house_length.setText(self._translate("TCP-UDP", "隔间长:"))
        self.label_sub_house_width.setText(self._translate("TCP-UDP", "隔间宽:"))
        self.label_person_location.setText(self._translate("TCP-UDP", "人员位置:"))

        self.label_written.setText(self._translate("TCP-UDP", "透明战场作战平台"))  # 透明战场作战平台 标签

        self.lineEdit_person_location.setPlaceholderText("例如：(1,1);(2,2)")

    # 得到墙体数据 signal_wall_rader_flush马上触发wall_rader_flush函数
    def wall_rader_flush(self, wall_list_x, wall_list_y,data_wall_front_length,data_wall_front_width,data_house_front_length,data_house_front_width):

        real_msg = "房长:" + str(data_wall_front_length)
        self.label_real_number_people.setText(real_msg)

        error_msg = "房宽:" + str(data_wall_front_width)
        self.label_error_number_people.setText(error_msg)

        real_msg = "隔间长:" + str(data_house_front_length)
        self.label_sub_house_length.setText(real_msg)

        error_msg = "隔间宽:" + str(data_house_front_width)
        self.label_sub_house_width.setText(error_msg)

        self.myfigure_rader.updata_figure_wall(wall_list_x, wall_list_y,'Radar',self.object_radar_x,self.object_radar_y)  # 激光画布下的墙体数据
        self.myfigure_laser.updata_figure_wall(wall_list_x, wall_list_y, 'Laser', self.object_laser_x,
                                               self.object_laser_y)  # 总画布下的墙体数据
        self.myfigure_fusion.updata_figure_fusion_wall(wall_list_x, wall_list_y,'Fusion',self.object_fusion_x,self.object_fusion_y)  # 总画布下的墙体数据


    def rader_flush(self, object_list):
        x_array = []
        y_array = []
        for point_X, point_Y in object_list:
            # if(len(self.object_x) >= 10):
            #     self.object_x.pop(0)
            #     self.object_y.pop(0)
            self.object_radar_x.append(float(point_X))
            self.object_radar_y.append(float(point_Y))
            x_array.append(float(point_X))
            y_array.append(float(point_Y))
        self.myfigure_rader.updata_figure(x_array, y_array, 'Radar',self.object_radar_x,self.object_radar_y)

    def laser_flush(self, object_list):
        x_array = []
        y_array = []
        for point_X, point_Y in object_list:
            self.object_laser_x.append(float(point_X))
            self.object_laser_y.append(float(point_Y))
            x_array.append(float(point_X))
            y_array.append(float(point_Y))
        self.myfigure_laser.updata_figure(x_array, y_array, 'Laser',self.object_laser_x,self.object_laser_y)

    def fusion_flush(self, fusion_list):

        detect_msg = "检测人数:" + str(len(fusion_list))
        self.label_detect_number_people.setText(detect_msg)

        x_array = []
        y_array = []

        for point_X, point_Y in fusion_list:
            self.object_fusion_x.append(float(point_X))
            self.object_fusion_y.append(float(point_Y))
            x_array.append(point_X)
            y_array.append(point_Y)

        self.myfigure_fusion.updata_figure_fusion(x_array, y_array, 'Fusion',self.object_fusion_x,self.object_fusion_y)

    # signal_write_rader_msg信号会触发这个函数 #雷达坐标文本浏览框触发信号
    def write_rader_msg(self, msg):
        self.textBrowser_recv_radar.insertPlainText(msg)
        # 滚动条移动到结尾
        self.textBrowser_recv_radar.moveCursor(QtGui.QTextCursor.End)

    # signal_write_laser_msg信号会触发这个函数  #激光文本浏览框
    def write_laser_msg(self, msg):
        self.textBrowser_recv_laser.insertPlainText(msg)
        # 滚动条移动到结尾
        self.textBrowser_recv_laser.moveCursor(QtGui.QTextCursor.End)

    # signal_write_fusion_msg信号会触发这个函数   #融合文本浏览框
    def write_fusion_msg(self, msg):
        self.textBrowser_recv_fusion.insertPlainText(msg)
        # 滚动条移动到结尾
        self.textBrowser_recv_fusion.moveCursor(QtGui.QTextCursor.End)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ui = ToolsUi(1)
    ui.show()
    sys.exit(app.exec_())
